//pingCode组件
/* eslint-disable no-unused-vars */
import get from '/@/utils/get'
import { Session } from '/@/utils/storage'
import common from '/@/common/common'

interface BaseType{
    getAccessToken(): Promise<void>
}

class PingCode implements BaseType{
    async getAccessToken(): Promise<void>{
        let token = await get.get('https://open.pingcode.com/v1/auth/token?'+
        'grant_type=client_credentials'+
        '&client_id=IqCslZyGueWf'+
        '&client_secret=iCgxdsYbwwunhcKwKptchPvh')
        Session.set('pingcode_access_token',token.data.access_token)
    }

    async getProject(): Promise<void>{
        if (common.objectUnavailable(Session.get('pingcode_access_token'))) {
			return this.getAccessToken()
		}
        let project = await get.get_config('https://open.pingcode.com/v1/project/projects',{'Authorization': 'Bearer ' + Session.get('pingcode_access_token')})
        project = project.data
    }

    async getWorkItem(): Promise<void>{
        if (common.objectUnavailable(Session.get('pingcode_access_token'))) {
			return this.getAccessToken()
		}
        let workItem = await get.get_config('https://open.pingcode.com/v1/project/work_items?'+
        'created_start_at='+Date.parse(new Date(Date.parse(new Date().toString()) - 1000 * 60 * 60 * 24 * 30).toString())/1000+
        '&include_archived=true'
        ,{'Authorization': 'Bearer ' + Session.get('pingcode_access_token')})
        workItem = workItem.data
        console.log(workItem)
    }
}

const pingCode = new PingCode()
export default pingCode